

import {
  Ajax
} from '../../util/api.js'
let ajax = new Ajax()


Page({

  /**
   * 页面的初始数据
   */
  data: {
    authorized:false,
    userInfo:null,
    bookCount:13,
    classics:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.userAuthorized()
    this.getMyBookCount()
    this.getMyFavor()
  },

  getMyFavor(){
    ajax.favor(res=>{
      this.setData({
        classics: res
      })
    })
  },

  getMyBookCount() { 
    
  },
  onPreviewTap(){
    // const bid = this.properties.book.id
    wx.navigateTo({
      url: `/pages/classic-detail/classic-detail`,
    })
  },
  userAuthorized(){
    wx.getSetting({
      success:data=>{
        if(data.authSetting['scope.userInfo']){
          wx.getUserInfo({
            success:data=>{
              this.setData({
                authorized:true,
                userInfo:data.userInfo
              })
            }
          })
        }
      }
    })
  },
  onGetUserInfo(e){
    const userInfo = e.detail.userInfo
    if(userInfo){
      this.setData({
        authorized:true,
        userInfo
      })
    }
  }
})